<template>
  <view class="settings-page">
    <!-- 状态栏高度 -->
    <view class="status-bar"></view>

    <!-- 头部区域 -->
    <view class="header">
      <view class="avatar-container">
        <image class="avatar" src="/static/default.png" mode="aspectFill"></image>
        <view class="avatar-edit">
          <uni-icons type="camera-filled" size="16" color="#fff"></uni-icons>
        </view>
      </view>
      <text class="username">张爷爷</text>
      <text class="user-id">ID: 2024001</text>
    </view>

    <!-- 设置列表 -->
    <view class="setting-list">
      <view
        class="setting-item"
        v-for="(item, index) in settings"
        :key="index"
        @click="navigateTo(item.path)"
        :class="{ last: index === settings.length - 1 }"
      >
        <view class="item-left">
          <view class="icon" :style="{ backgroundColor: item.color }">
            <uni-icons :type="item.icon" size="20" color="#fff"></uni-icons>
          </view>
          <text class="label">{{ item.label }}</text>
        </view>
        <view class="item-right">
          <text class="badge" v-if="item.badge">{{ item.badge }}</text>
          <uni-icons type="right" size="18" color="#c0c4cc" class="arrow"></uni-icons>
        </view>
      </view>
    </view>

    <!-- 退出登录按钮 -->
    <view class="logout-section">
      <view class="logout-btn" @click="handleLogout">
        <text class="logout-text">退出登录</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue';

// 设置列表数据
const settings = ref([
  { label: '个人信息', icon: 'person', path: '/pages/profile/index', color: '#ff6b6b', badge: '' },
  {
    label: '账号安全',
    icon: 'locked',
    path: '/pages/security/index',
    color: '#4ecdc4',
    badge: '新',
  },
  {
    label: '通知设置',
    icon: 'sound',
    path: '/pages/notifications/index',
    color: '#45b7d1',
    badge: '',
  },
  { label: '隐私设置', icon: 'gear', path: '/pages/privacy/index', color: '#96ceb4', badge: '' },
  { label: '帮助与反馈', icon: 'help', path: '/pages/help/index', color: '#feca57', badge: '' },
  {
    label: '关于我们',
    icon: 'info',
    path: '/pages/about/index',
    color: '#ff9ff3',
    badge: 'V2.1.0',
  },
]);

// 跳转函数
const navigateTo = (path) => {
  uni.navigateTo({
    url: path,
  });
};

// 退出登录
const handleLogout = () => {
  uni.showModal({
    title: '提示',
    content: '确定要退出登录吗？',
    success: (res) => {
      if (res.confirm) {
        uni.showToast({
          title: '已退出登录',
          icon: 'success',
        });
        // 这里添加实际的退出逻辑
      }
    },
  });
};
</script>

<style scoped>
.settings-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
}

.status-bar {
  height: var(--status-bar-height);
}

.header {
  padding: 40rpx 30rpx 30rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 0 0 30rpx 30rpx;
  margin-bottom: 30rpx;
}

.avatar-container {
  position: relative;
  margin-bottom: 20rpx;
}

.avatar {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  border: 4rpx solid rgba(255, 255, 255, 0.3);
  background-color: #fff;
}

.avatar-edit {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 40rpx;
  height: 40rpx;
  background: #ff6b6b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2rpx solid #fff;
}

.username {
  font-size: 36rpx;
  font-weight: 600;
  margin-bottom: 10rpx;
}

.user-id {
  font-size: 24rpx;
}

.setting-list {
  background-color: #fff;
  border-radius: 20rpx;
  margin: 0 30rpx 40rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 30rpx;
  border-bottom: 1rpx solid #f0f0f0;
  transition: all 0.3s ease;
  position: relative;
}

.setting-item:active {
  background-color: #f8f9fa;
}

.setting-item.last {
  border-bottom: none;
}

.item-left {
  display: flex;
  align-items: center;
  flex: 1;
}

.icon {
  width: 60rpx;
  height: 60rpx;
  border-radius: 12rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20rpx;
}

.label {
  font-size: 32rpx;
  color: #333;
  font-weight: 500;
}

.item-right {
  display: flex;
  align-items: center;
}

.badge {
  background: #ff4757;
  color: #fff;
  font-size: 20rpx;
  padding: 4rpx 12rpx;
  border-radius: 20rpx;
  margin-right: 15rpx;
}

.arrow {
  opacity: 0.6;
}

.logout-section {
  padding: 0 30rpx;
}

.logout-btn {
  background: #fff;
  border-radius: 15rpx;
  padding: 30rpx;
  text-align: center;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
}

.logout-btn:active {
  background: #f8f9fa;
  transform: scale(0.98);
}

.logout-text {
  font-size: 32rpx;
  color: #ff4757;
  font-weight: 500;
}
</style>
